/*
 * Package il.ac.biu.cs.grossmm.api_tests.keys
 * File PatternIntersection.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.junit_api_tests.keys;
import il.ac.biu.cs.grossmm.api.keys.KeyPattern;

import org.junit.Test;
import static org.junit.Assert.*;

import static il.ac.biu.cs.grossmm.impl.keys.PatternOperations.*;
import static il.ac.biu.cs.grossmm.api.presence.BaseVocabulary.*;
import static il.ac.biu.cs.grossmm.api.keys.KeyPattern.*;
import static il.ac.biu.cs.grossmm.api.keys.PatternFactory.*;


public class PatternIntersectionTest {
	private void check(KeyPattern p1, KeyPattern p2, KeyPattern expected) {
		KeyPattern result = intersection(p1, p2);
		assertEquals(expected, result);
	}
	
	@Test
	public void test1() {
		check(
			pattern(),
			pattern(),
			pattern()
		);
	}
	
	@Test
	public void test2() {
		check(
			pattern(),
			ANY_KEY,
			pattern()
		);
	}
	
	@Test
	public void test3() {
		check(
			ANY_KEY,
			NONE,
			NONE
		);
	}
	
	@Test
	public void test4() {
		check(
			ANY_KEY,
			ANY_SIMPLE_KEY,
			ANY_SIMPLE_KEY
		);
	}
	
	@Test
	public void test5() {
		check(
			pattern(String.class),
			ANY_SIMPLE_KEY,
			pattern(String.class)
		);
	}
	
	@Test
	public void test6() {
		check(
			ANY_SIMPLE_KEY,
			pattern("Presence"),
			pattern("Presence")
		);
	}
	
	@Test
	public void test7() {
		check(
			ANY_SIMPLE_KEY,
			pattern("Presence", mandatory(CONTENT_TYPE)),
			NONE
		);
	}
	
	@Test
	public void test8() {
		check(
			maskPattern(String.class),
			pattern("Presence", mandatory(CONTENT_TYPE)),
			pattern("Presence", mandatory(CONTENT_TYPE))
		);
	}
	
	@Test
	public void test9() {
		check(
			maskPattern("Presence"),
			pattern(String.class, mandatory(CONTENT_TYPE)),
			pattern("Presence", mandatory(CONTENT_TYPE))
		);
	}
	
	@Test
	public void test10() {
		check(
			pattern(Integer.class),
			pattern(String.class, optional(CONTENT_TYPE)),
			pattern(Void.class)
		);
	}
	
	@Test
	public void test11() {
		check(
			maskPattern(Integer.class),
			maskPattern(String.class, mandatory(CONTENT_TYPE)),
			maskPattern(Void.class, mandatory(CONTENT_TYPE))
		);
	}
	
	@Test
	public void test12() {
		check(
			maskPattern(Integer.class, 
				optional(RESOURCE_TYPE)),
			maskPattern(String.class, 
				mandatory(CONTENT_TYPE)),
			maskPattern(Void.class, 
				mandatory(CONTENT_TYPE), optional(RESOURCE_TYPE))
		);
	}
}
